#!/usr/bin/env python
# coding: utf-8

# In[51]:


import requests 


# In[52]:


host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=1jynZTHeY3sQLKnB43fM8gip&client_secret=oGxozSTGnRwqs9KsbrDHj1crcuLK0nva'
response = requests.get(host)
if response:
    print(response.json())


# In[53]:


access_token = '24.58f53419da54e4f7466af557e16fab84.2592000.1613817469.282335-23573027'


# In[54]:


# encoding:utf-8

import requests
import base64

'''
地标识别
'''

request_url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/landmark"
# 二进制方式打开图片文件
f = open('/Users/andemundgarcia/Desktop/api-期末/img/blsmy.jpg', 'rb')
img = base64.b64encode(f.read())
params = {"image":img}
request_url = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/landmark?access_token='+access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
    print (response.json())


# In[55]:


# encoding:utf-8

import requests
import base64

'''
货币识别
'''

request_url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/currency"
# 二进制方式打开图片文件
f = open('/Users/andemundgarcia/Desktop/api-期末/img/ouyuan.jpg', 'rb')
img = base64.b64encode(f.read())
params = {"image":img}
request_url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/currency?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
    print (response.json())


# In[56]:


# encoding:utf-8

import requests
import base64

'''
通用文字识别
'''

request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic"
# 二进制方式打开图片文件
f = open('/Users/andemundgarcia/Desktop/api-期末/img/lupai.jpg', 'rb')
img = base64.b64encode(f.read())

params = {"image":img}
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
    print (response.json())

